package bavaria.hightech.banking.statement;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.text.NumberFormat;
import java.util.ResourceBundle;

import bavaria.hightech.banking.account.Account;

public class PlainTextStatementFormatter implements StatementFormatter {
	@Override
	public void getStatement(Account account, OutputStream outputStream)
			throws IOException {
		ResourceBundle bundle = ResourceBundle
				.getBundle("i18n/AccountStatementBundle");
		Writer writer = new BufferedWriter(new OutputStreamWriter(outputStream));
		writer.write(bundle.getString("accountNumber") + ": "
				+ account.getNumber() + '\n');
		writer.write(bundle.getString("accountHolder") + ": "
				+ account.getAccountHolder() + '\n');
		NumberFormat formatter = NumberFormat.getCurrencyInstance();
		String formatted = formatter.format(account.getBalance()
				.getBigInteger());
		writer.write(bundle.getString("balance") + ": " + formatted + '\n');
		writer.write(bundle.getString("booking") + ": "
				+ account.getStatement());
		writer.flush();
	}
}
